package com.wb3.organizer.quartz;

import java.util.List;

import org.apache.log4j.Logger;

import com.wb3.organizer.model.Account;
import com.wb3.organizer.model.Appointment;
import com.wb3.organizer.model.Task;
import com.wb3.organizer.service.MailService;

public class SendMailJob {

	private static Logger log = Logger.getLogger(SendMailJob.class);

	private MailService mailService;

	public MailService getMailService() {
		return mailService;
	}

	public void setMailService(MailService mailService) {
		this.mailService = mailService;
	}

	public void execute() {
		List<Account> mailAccount = mailService.getMailAccount();
		List<Appointment> mailApp = mailService.getMailAppointment(mailAccount);
		List<Task> mailTask = mailService.getMailTask(mailAccount);
		
		for(int i=0; i<mailApp.size(); i++){
			Appointment appointment = mailApp.get(i);
			mailService.sendMail(appointment.getAccount().getEmail(), "定时计划提醒", "<html><head></head><body><h1>您今天有到期的计划：" + appointment.getSubject() +"</h1></body></html");
			log.info("邮件已发送 " + appointment.getAccount().getUsername() + "\n");
		}
		
		for(int i=0; i<mailTask.size(); i++){
			Task task = mailTask.get(i);
			mailService.sendMail(task.getAccount().getEmail(), "定时计划提醒", "<html><head></head><body><h1>您今天有到期的任务：" + task.getSubject() +"</h1></body></html");
			log.info("邮件已发送 " + task.getAccount().getUsername() + "\n");
		}
	}

}
